/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tracker.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : 12 November 2012
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
 */
@Entity
@Table(name = "Users")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UsersEntity.findAll", query = "SELECT u FROM UsersEntity u"),
    @NamedQuery(name = "UsersEntity.findByUserId", query = "SELECT u FROM UsersEntity u WHERE u.userId = :userId"),
    @NamedQuery(name = "UsersEntity.findByUserName", query = "SELECT u FROM UsersEntity u WHERE u.userName = :userName"),
    @NamedQuery(name = "UsersEntity.findByPassword", query = "SELECT u FROM UsersEntity u WHERE u.password = :password"),
    @NamedQuery(name = "UsersEntity.findByUserLevel", query = "SELECT u FROM UsersEntity u WHERE u.userLevel = :userLevel"),
    @NamedQuery(name = "UsersEntity.findBySeedAmount", query = "SELECT u FROM UsersEntity u WHERE u.seedAmount = :seedAmount"),
    @NamedQuery(name = "UsersEntity.findByLeechAmount", query = "SELECT u FROM UsersEntity u WHERE u.leechAmount = :leechAmount"),
    @NamedQuery(name = "UsersEntity.checkLogin", query = "SELECT u FROM UsersEntity u WHERE u.userName = :userName and u.password = :password")})
public class UsersEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //Auto-Increment
    @Basic(optional = false)
    @NotNull
    @Column(name = "UserId")
    private Integer userId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "UserName")
    private String userName;
    @Size(max = 20)
    @Column(name = "Password")
    private String password;
    @Column(name = "UserLevel")
    private Integer userLevel;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "SeedAmount")
    private Float seedAmount;
    @Column(name = "LeechAmount")
    private Float leechAmount;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
    private Collection<CommentsEntity> commentsEntityCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
    private Collection<PointsEntity> pointsEntityCollection;

    public UsersEntity() {
    }

    public UsersEntity(Integer userId) {
        this.userId = userId;
    }

    public UsersEntity(Integer userId, String userName) {
        this.userId = userId;
        this.userName = userName;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(Integer userLevel) {
        this.userLevel = userLevel;
    }

    public Float getSeedAmount() {
        return seedAmount;
    }

    public void setSeedAmount(Float seedAmount) {
        this.seedAmount = seedAmount;
    }

    public Float getLeechAmount() {
        return leechAmount;
    }

    public void setLeechAmount(Float leechAmount) {
        this.leechAmount = leechAmount;
    }

    @XmlTransient
    public Collection<CommentsEntity> getCommentsEntityCollection() {
        return commentsEntityCollection;
    }

    public void setCommentsEntityCollection(Collection<CommentsEntity> commentsEntityCollection) {
        this.commentsEntityCollection = commentsEntityCollection;
    }

    @XmlTransient
    public Collection<PointsEntity> getPointsEntityCollection() {
        return pointsEntityCollection;
    }

    public void setPointsEntityCollection(Collection<PointsEntity> pointsEntityCollection) {
        this.pointsEntityCollection = pointsEntityCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UsersEntity)) {
            return false;
        }
        UsersEntity other = (UsersEntity) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "tracker.entity.UsersEntity[ userId=" + userId + " ]";
    }

}
